/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Selenium;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

/**
 *
 * @author Lone_Wolf
 */
public class leech_buploads {

    private WebDriver driver;

    public leech_buploads() {
        //set location of chromedriver.exe
        System.setProperty("webdriver.chrome.driver",
                "C:\\chromedriver.exe");
        //create chromedriver
        driver = new ChromeDriver();
        //driver.manage().window().setPosition(new Point(1921, 1081));
        getMainPage();
    }

    public void quitDriver() {
        driver.quit();
    }

    private void getMainPage() {
        driver.get("http://leech.buploads.com");
    }

    public String submitLink(String link) {
        String download_link = "";
        
        //insert link
        WebElement element = driver.findElement(By.id("input"));
        element.clear();
        element.sendKeys(link + "\n");

        //select indirect download
        element = driver.findElement(By.id("submit_nodirect"));
        
        //start remote download
        element.click();

        //when page is loaded
        element = driver.findElement(By.className("link"));
        element = element.findElement(By.tagName("a"));
        System.out.println(element.getText().substring(element.getText().indexOf("leechmafia.com_") + 15));
        download_link = element.getAttribute("href");
        System.out.println(download_link);
        
        quitDriver();
        
        return download_link;
    }
}
